/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GestionarProductos.java
 *
 * Created on 10/06/2009, 09:30:30 PM
 */

package CRM_UI;

import DAO.DAOArticulo;
import DAO.DAOProducto;
import LogicaNegocio.*;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author L¡z
 */
public class GestionarProductos extends javax.swing.JFrame
{
    Vector <Vector> productosTabla; //filas de tabla
    Vector <String> nombreColumnas; //columnas de la tabla
    String idSeleccionado;

    public GestionarProductos() 
    {
        productosTabla= new Vector<Vector>();

        //clave
        inicializarColumnas();
        consultarProductos();
        initComponents();

    }
//llenar nombre de columnas
    public void inicializarColumnas()
    {
        nombreColumnas= new Vector<String>();
        nombreColumnas.addElement("Id");
        nombreColumnas.addElement("Nombre");
        nombreColumnas.addElement("Precio Venta");
        nombreColumnas.addElement("Id Categoría");
        nombreColumnas.addElement("Costo de Fabricación");
        nombreColumnas.addElement("Presentación");
        nombreColumnas.addElement("Fecha de Fabricación");
        nombreColumnas.addElement("Fecha de Vencimiento");
        nombreColumnas.addElement("Años de Garantía");
        

    }

    public void actualizarTabla()
    {
        tablaProductos.setModel(new DefaultTableModel (productosTabla, nombreColumnas));
    }

    public void consultarProductos()
    {
        DAOProducto daoProducto= new DAOProducto();
        Vector<Producto> vectorProductos= new Vector<Producto>();
        vectorProductos = daoProducto.consultarProductos();

        System.out.println(vectorProductos.size());

        for(int i=0; i<vectorProductos.size(); i++)
        {
            Vector producto= new Vector() ; //cada fila o tupla de la tabla
            producto.addElement(vectorProductos.elementAt(i).getCodigoArticulo());
            producto.addElement(vectorProductos.elementAt(i).getNombreArticulo());
            producto.addElement(vectorProductos.elementAt(i).getPrecioVentaArticulo());
            producto.addElement(vectorProductos.elementAt(i).getCodigoCategoria());
            producto.addElement(vectorProductos.elementAt(i).getCostoFabricacion());
            producto.addElement(vectorProductos.elementAt(i).getPresentacion());
            producto.addElement(vectorProductos.elementAt(i).getFechaFabricacion());
            producto.addElement(vectorProductos.elementAt(i).getFechaVencimiento());
            producto.addElement(vectorProductos.elementAt(i).getAñosGarantia());

            productosTabla.addElement(producto);
        }


    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaProductos = new javax.swing.JTable(productosTabla, nombreColumnas);
        jPanel2 = new javax.swing.JPanel();
        botonCrear = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        textFieldId = new javax.swing.JTextField();
        textFieldNombre = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        textFieldCostoFab = new javax.swing.JTextField();
        diaComboBoxF = new javax.swing.JComboBox();
        mesComboBoxF = new javax.swing.JComboBox();
        aNoComboBoxF = new javax.swing.JComboBox();
        botonModificar = new javax.swing.JButton();
        diaComboBoxV = new javax.swing.JComboBox();
        comboBoxAñosGarantia = new javax.swing.JComboBox();
        mesComboBoxV = new javax.swing.JComboBox();
        aNoComboBoxV = new javax.swing.JComboBox();
        jTextField1 = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        textFieldCategoria = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        textFieldPresentacion = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        botonEliminar = new javax.swing.JButton();

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Productos"));

        /*
        tablaProductos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "Identificador", "Presentacion", "Fecha de Fabricación", "Fecha de Vencimiento", "Costo de Fabricación", "Años de Garantía"
            }
        ));
        */
        tablaProductos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tablaProductosMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tablaProductos);

        jScrollPane2.setViewportView(jScrollPane1);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 469, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Modificar"));

        botonCrear.setText("crear");
        botonCrear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonCrearActionPerformed(evt);
            }
        });

        jLabel1.setText("Identificador:");

        jLabel2.setText("Presentacion:");

        jLabel3.setText("Fecha de Fabricación:");

        jLabel4.setText("Fecha de Vencimiento:");

        textFieldId.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textFieldIdActionPerformed(evt);
            }
        });

        jLabel5.setText("Costo de Fabricación:");

        jLabel6.setText("Años de Garantía:");

        diaComboBoxF.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));

        mesComboBoxF.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" }));

        aNoComboBoxF.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1980", "1981", "1982", "1983", "1984", "1985", "1986", "1987", "1988", "1989", "1990", "1991", "1992", "1993", "1994", "1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009" }));

        botonModificar.setText("modificar");
        botonModificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonModificarActionPerformed(evt);
            }
        });

        diaComboBoxV.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));

        comboBoxAñosGarantia.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));

        mesComboBoxV.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" }));

        aNoComboBoxV.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1980", "1981", "1982", "1983", "1984", "1985", "1986", "1987", "1988", "1989", "1990", "1991", "1992", "1993", "1994", "1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009" }));

        jLabel7.setText("Precio Venta:");

        jLabel8.setText("Categoria:");

        jLabel9.setText("Presentación:");

        botonEliminar.setText("eliminar");
        botonEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonEliminarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(jLabel7)
                            .addComponent(jLabel5)
                            .addComponent(jLabel8)
                            .addComponent(jLabel9))
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(14, 14, 14)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(textFieldNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 258, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(textFieldId, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(comboBoxAñosGarantia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(diaComboBoxF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(mesComboBoxF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(aNoComboBoxF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addComponent(jTextField1, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                                                .addComponent(diaComboBoxV, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(mesComboBoxV, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addComponent(textFieldCostoFab, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(textFieldCategoria, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(textFieldPresentacion, javax.swing.GroupLayout.Alignment.LEADING))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(aNoComboBoxV, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))))
                    .addComponent(jLabel6))
                .addContainerGap(99, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(145, Short.MAX_VALUE)
                .addComponent(botonCrear)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botonModificar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botonEliminar)
                .addGap(131, 131, 131))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(textFieldId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(15, 15, 15)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2)
                    .addComponent(textFieldNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(8, 8, 8)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(diaComboBoxF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(mesComboBoxF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(aNoComboBoxF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(diaComboBoxV, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(mesComboBoxV, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(aNoComboBoxV, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textFieldCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addGap(10, 10, 10)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textFieldCostoFab, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textFieldPresentacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addGap(13, 13, 13)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(comboBoxAñosGarantia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botonEliminar)
                    .addComponent(botonModificar)
                    .addComponent(botonCrear))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void botonEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonEliminarActionPerformed
        // TODO add your handling code here:
        int option = JOptionPane.showConfirmDialog(null, "¡Está¡ seguro que desea borrar el producto?", "Eliiminar Producto" , JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
        if(option == 0)
        {
            DAOProducto daoProducto = new DAOProducto();
            DAOArticulo daoArticulo= new DAOArticulo();
            int i = daoProducto.eliminarProducto(idSeleccionado);
            int j=daoArticulo.eliminarArticulo(idSeleccionado);
            System.out.print("Se han borrado " + i + " articulo"+" y "+j+" producto"+ " de la BD\n");
            

            consultarProductos();
            actualizarTabla();
        }
}//GEN-LAST:event_botonEliminarActionPerformed

    private void botonCrearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonCrearActionPerformed
        String fechaF =diaComboBoxF.getSelectedItem().toString()+"-"+mesComboBoxF.getSelectedItem().toString()+"-"+aNoComboBoxF.getSelectedItem().toString();
        int i,j;
        i=j=0;
        DAOProducto daoProducto= new DAOProducto();
        DAOArticulo daoArticulo= new DAOArticulo();
        Producto producto= new Producto(textFieldId.getText(), textFieldNombre.getText(), Integer.parseInt(textFieldCostoFab.getText()),
                                     textFieldCategoria.getText(),"1245670004", Integer.parseInt(textFieldCostoFab.getText()),textFieldPresentacion.getText(), "12-05-2009",
                                     "12-05-2010", Integer.parseInt(comboBoxAñosGarantia.getSelectedItem().toString()));

        Articulo articulo = new Articulo(textFieldId.getText(), textFieldNombre.getText(), Integer.parseInt(textFieldCostoFab.getText()),
                                         textFieldCategoria.getText(),"1245670004");
        j= daoArticulo.guardarArticulo(articulo);
        
        
      
        if(j==1)
        {
            i= daoProducto.guardarProducto(producto);
            JOptionPane.showMessageDialog(null, "Se ha insertado "+i+" nuevo Producto", "Producto Nuevo", JOptionPane.INFORMATION_MESSAGE);
        }

        else
        {
           JOptionPane.showMessageDialog(this, "Error de inserciÃ³n .", "AutentificaciÃ³n errÃ³nea.", JOptionPane.ERROR_MESSAGE);
           
        }
        
        System.out.print("Se han insertado " + i + " producto"+" y "+ j+" articulo "+" a la BD\n");
        

        consultarProductos();
        actualizarTabla();
}//GEN-LAST:event_botonCrearActionPerformed

    private void textFieldIdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textFieldIdActionPerformed
        // TODO add your handling code here:
        
        

}//GEN-LAST:event_textFieldIdActionPerformed


    private void botonModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonModificarActionPerformed
        DAOProducto daoProducto= new DAOProducto();
        DAOArticulo daoArticulo= new DAOArticulo();

        Producto producto= new Producto(textFieldId.getText(), textFieldNombre.getText(), Integer.parseInt(textFieldCostoFab.getText()),
                                     textFieldCategoria.getText(),"1245670004", Integer.parseInt(textFieldCostoFab.getText()),textFieldPresentacion.getText(), "12-05-2009",
                                     "12-05-2010", Integer.parseInt(comboBoxAñosGarantia.getSelectedItem().toString()));

        Articulo articulo = new Articulo(textFieldId.getText(), textFieldNombre.getText(), Integer.parseInt(textFieldCostoFab.getText()),
                                         textFieldCategoria.getText(),"1245670004");

        int i= daoProducto.modificarCostoFabricacionProducto(producto);
            daoProducto.modificarPresentacionProducto(producto);
            daoProducto.modificarFechaFabricacionProducto(producto);
            daoProducto.modificarFechaVencimientoProducto(producto);
            daoProducto.modificarAñosGarantiaProducto(producto);

        int j= daoArticulo.modificarNombreArticulo(articulo);
            daoArticulo.modificarPrecioVentaArticulo(articulo);
            daoArticulo.modificarCodigoCategoriaArticulo(articulo);
            daoArticulo.modificarCcEmpleadoArticulo(articulo);


        System.out.print("Se han modificado " + i + " producto"+" y "+ j+" articulo "+" en la BD\n");
        
        consultarProductos();
        actualizarTabla();
}//GEN-LAST:event_botonModificarActionPerformed


    private void textFieldCostoFabActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textFieldPrecioVentaActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_textFieldPrecioVentaActionPerformed

    private void textFieldCategoriaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textFieldCategoriaActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_textFieldCategoriaActionPerformed

    private void tablaProductosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaProductosMouseClicked
        // TODO add your handling code here:
        int fila= tablaProductos.getSelectedRow();
        idSeleccionado=tablaProductos.getValueAt(fila, 0).toString();
        textFieldId.setText(idSeleccionado);

        textFieldNombre.setText(tablaProductos.getValueAt(fila, 1).toString());
        textFieldCostoFab.setText(tablaProductos.getValueAt(fila, 2).toString());
        textFieldCategoria.setText(tablaProductos.getValueAt(fila, 3).toString());
        textFieldCostoFab.setText(tablaProductos.getValueAt(fila, 4).toString());
        textFieldPresentacion.setText(tablaProductos.getValueAt(fila, 5).toString());
        comboBoxAñosGarantia.setSelectedItem(tablaProductos.getValueAt(fila, 8).toString());

        
        
}//GEN-LAST:event_tablaProductosMouseClicked

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {

        try {
            // Set System L&F
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        catch (UnsupportedLookAndFeelException e)
        {
           // handle exception
        }
        catch (ClassNotFoundException e)
        {
           // handle exception
        }
        catch (InstantiationException e)
        {
           // handle exception
        }
        catch (IllegalAccessException e)
        {
           // handle exception
        }

        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GestionarProductos().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox aNoComboBoxF;
    private javax.swing.JComboBox aNoComboBoxV;
    private javax.swing.JButton botonCrear;
    private javax.swing.JButton botonEliminar;
    private javax.swing.JButton botonModificar;
    private javax.swing.JComboBox comboBoxAñosGarantia;
    private javax.swing.JComboBox diaComboBoxF;
    private javax.swing.JComboBox diaComboBoxV;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JComboBox mesComboBoxF;
    private javax.swing.JComboBox mesComboBoxV;
    private javax.swing.JTable tablaProductos;
    private javax.swing.JTextField textFieldCategoria;
    private javax.swing.JTextField textFieldCostoFab;
    private javax.swing.JTextField textFieldId;
    private javax.swing.JTextField textFieldNombre;
    private javax.swing.JTextField textFieldPresentacion;
    // End of variables declaration//GEN-END:variables

}
